﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Soundteller.Common.Tests;
using Soundteller.Visual.Model;
using Soundteller.Visual.Model.Interfaces;
using Soundteller.Visual.Repositories;
using Soundteller.Visual.Repositories.Interfaces;

namespace Soundteller.Visual.Tests.Unit.Repositories.GraphicBufferRepositorySpecifications
{
    public abstract class WhenPeek : TestBase
    {
        protected IGraphicBufferRepository GraphicBufferRepository { get; private set; }
        protected Mock<IMemoryContext> MemoryContext { get; private set; }
        protected GraphicBase Result { get; private set; }

        protected override void Arrange()
        {
            MemoryContext = new Mock<IMemoryContext>();
            MemoryContext.Setup(c => c.GraphicBuffer).Returns(new Stack<GraphicBase>());

            GraphicBufferRepository = new GraphicBufferRepository(MemoryContext.Object);
        }

        protected override void Act()
        {
            Result = GraphicBufferRepository.Peek();
        }
    }

    [TestClass]
    public class WhenPeekGivenEmptyBuffer : WhenPeek
    {
        [TestMethod]
        public void ThenResultShouldBeEmpty()
        {
            Assert.IsNull(Result);
        }
    }

    [TestClass]
    public class WhenPeekGivenOneItemInBuffer : WhenPeek
    {
        private GeneratedGraphic _itemInBuffer;

        protected override void Arrange()
        {
            base.Arrange();
            _itemInBuffer = new GeneratedGraphic();
            GraphicBufferRepository.Push(_itemInBuffer);
        }

        [TestMethod]
        public void ThenResultShouldNotBeEmpty()
        {
            Assert.IsNotNull(Result);
            Assert.AreEqual(_itemInBuffer, Result);
        }
    }
}
